package servlet;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.liudecai.utils.common.CommonUtils;

import bean.RequestBean;
import dao.Request2BeanDao;


@WebServlet("/Request2BeanServlet")
public class Request2BeanServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
    public Request2BeanServlet() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String str = request.getParameter("other");
		System.out.println(str);
		
		RequestBean bean = CommonUtils.MyReqest2Bean(request, response, RequestBean.class);
		System.out.println("没有的属性被过滤省略不显示："+bean);
		Request2BeanDao dao = new Request2BeanDao();
		try {
			dao.Add(bean);
		} catch (SQLException e) {
			System.out.println("添加数据出错!");
			e.printStackTrace();
		}
		response.getWriter().append("Served at: ").append(request.getContextPath()+"<br>");
		response.getWriter().write("没有的属性被过滤省略不显示：  username="+bean.getUsername()+"  password="+bean.getPassword()+"  telephone="+bean.getTelephone());
		response.getWriter().append("<br> 数据已经添加到数据库了。");
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
